package windbell.domain.risk.impl;

import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;
import windbell.domain.risk.RiskCheckTemplate;
import windbell.domain.risk.RiskCheckTemplateCriteria;
import windbell.domain.risk.RiskCheckTemplateOwner;

public class RiskCheckTemplateCriteriaImpl extends HQLBasedPagedQueryCriteria<RiskCheckTemplate> implements RiskCheckTemplateCriteria {
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public RiskCheckTemplateCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  private RiskCheckTemplateOwner owner;
  
  public RiskCheckTemplateOwner getOwner() {
    return this.owner;
  }
  
  public RiskCheckTemplateCriteria setOwner(final RiskCheckTemplateOwner owner) {
    this.owner = owner;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from windbell.domain.risk.impl.RiskCheckTemplateImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and ((this.name  LIKE :info) or (this.description  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner()) ){
    	hql += " and ((this.owner) = (:owner))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner())){
    	query.setParameter("owner",getOwner()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RiskCheckTemplateCriteriaImpl() {
    initOrderBys();
  }
}
